package util;

import javax.swing.*;
import java.awt.*;

/**
 * Some useful utilities, that can't be referred to other classes.<br>
 * <br>
 *
 * @author Mihail A. Muhin
 */
public class Util {

  /**
   * Outputs error message for the error occured due to illegal code.<br>
   * <br>
   *
   * @param ErrMsg error message
   */
  public static void ShowDebugError(String ErrMsg) {
    System.out.println(ErrMsg);
  }

  /**
   * Outputs error message, so that it is seen by user.<br>
   * <br>
   *
   * @param ErrMsg error message
   */
  public static void ShowUserError(String ErrMsg) {
    System.out.println(ErrMsg);
  }

  /**
   * Outputs exception info.<br>
   * <br>
   *
   * @param e - exception to print info about.
   */
  public static void PrintException(Exception e) {
    System.out.println("---Exception info");
    System.out.println("Exception class: ".concat(e.getClass().getName()));
    System.out.println("Error message: ".concat(e.getMessage()));
    System.out.println("-Stack");
    e.printStackTrace();
    System.out.println("-Stack end");
    System.out.println("---Exception info end");
  }

  public static void ShowDialog(String caption,String text) {
    JDialog dlg = new JDialog();
    JLabel l = new JLabel(text);

    l.setForeground(new Color(0, 0, 0));

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    dlg.setTitle(caption);
    dlg.getContentPane().setLayout(new BorderLayout());
    dlg.getContentPane().add(l, BorderLayout.CENTER);
    dlg.pack();
    dlg.setSize(dlg.getWidth(), dlg.getHeight() + 30);
    dlg.setLocation((int) (d.getWidth() - l.getWidth()) / 2, (int) (d.getHeight() - l.getHeight()) / 2);
    dlg.setModal(true);
    dlg.setVisible(true);
  }
}
